<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Carp::Assert - executable comments - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Carp-Assert - MetaCPAN" href="https://metacpan.org/dist/Carp-Assert/releases.rss" />
        <link rel="canonical" href="./Carp::Assert.html" />
        <meta name="description" content="executable comments" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Carp::Assert" />
<meta name="twitter:title"       content="Carp::Assert" />
<meta name="twitter:description" content="executable comments" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Carp::Assert.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Carp-Assert was released.">
      <span class="relatize">04 Mar 2023 14:10:43 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Carp-Assert">Carp-Assert</a>
  </li>
  <li>
    Module version: 0.22
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Carp-Assert/source/lib/Carp/Assert.pm">Source</a>
    (<a href="https://metacpan.org/dist/Carp-Assert/source/lib/Carp/Assert.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Carp-Assert/source/lib/Carp">Browse</a>
    (<a href="https://metacpan.org/dist/Carp-Assert/source/lib/Carp?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Carp-Assert/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Carp-Assert/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/demerphq/Carp-Assert">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Carp-Assert">Issues</a>
      (0)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Carp-Assert+0.22" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/C/Carp-Assert.html?oncpan=1&amp;distmat=1&amp;version=0.22&amp;grade=2" style="color: #090">26</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/C/Carp-Assert.html?oncpan=1&amp;distmat=1&amp;version=0.22&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/C/Carp-Assert.html?oncpan=1&amp;distmat=1&amp;version=0.22&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/YVES/Carp-Assert-0.22">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Carp-Assert who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 2
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Carp-Assert-0.22/index.html">94.53% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.6.0
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Carp-Assert/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/Y/YV/YVES/Carp-Assert-0.22.tar.gz">
      Download (<span itemprop="fileSize">11.08KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FYVES%2FCarp-Assert-0.22%2Flib%2FCarp%2FAssert.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Carp-Assert/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Carp-Assert/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Carp-Assert">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Carp-Assert">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Carp/Assert.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="YVES/Carp-Assert-0.22"
>0.22
  (YVES on 2023-03-04)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.20"
>0.20
  (MSCHWERN on 2007-01-05)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.19"
>0.19
  (MSCHWERN on 2007-01-02)</option>
<optgroup label="BackPAN">'
<option
  
  value="NEILB/Carp-Assert-0.21"
>0.21
  (NEILB on 2014-06-25)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.18"
>0.18
  (MSCHWERN on 2004-03-03)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.17"
>0.17
  (MSCHWERN on 2001-10-01)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.16"
>0.16
  (MSCHWERN on 2001-09-09)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.15"
>0.15
  (MSCHWERN on 2001-08-22)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.13"
>0.13
  (MSCHWERN on 2001-02-09)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.12"
>0.12
  (MSCHWERN on 2001-02-07)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.11"
>0.11
  (MSCHWERN on 2000-06-02)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.10"
>0.10
  (MSCHWERN on 2000-03-13)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.08"
>0.08
  (MSCHWERN on 1999-12-23)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.07"
>0.07
  (MSCHWERN on 1999-10-13)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.06"
>0.06
  (MSCHWERN on 1999-04-29)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/YVES/Carp-Assert-0.22/diff/' + encodeURIComponent(this.value) + '/lib/Carp/Assert.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="YVES/Carp-Assert-0.22"
>0.22
  (YVES on 2023-03-04)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.20"
>0.20
  (MSCHWERN on 2007-01-05)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.19"
>0.19
  (MSCHWERN on 2007-01-02)</option>
<optgroup label="BackPAN">'
<option
  
  value="NEILB/Carp-Assert-0.21"
>0.21
  (NEILB on 2014-06-25)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.18"
>0.18
  (MSCHWERN on 2004-03-03)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.17"
>0.17
  (MSCHWERN on 2001-10-01)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.16"
>0.16
  (MSCHWERN on 2001-09-09)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.15"
>0.15
  (MSCHWERN on 2001-08-22)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.13"
>0.13
  (MSCHWERN on 2001-02-09)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.12"
>0.12
  (MSCHWERN on 2001-02-07)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.11"
>0.11
  (MSCHWERN on 2000-06-02)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.10"
>0.10
  (MSCHWERN on 2000-03-13)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.08"
>0.08
  (MSCHWERN on 1999-12-23)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.07"
>0.07
  (MSCHWERN on 1999-10-13)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.06"
>0.06
  (MSCHWERN on 1999-04-29)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Carp" title="Carp" class="ellipsis">Carp</a></li>
  <li><a href="https://metacpan.org/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li>
  <li><a href="https://metacpan.org/pod/strict" title="strict" class="ellipsis">strict</a></li>
  <li><a href="https://metacpan.org/pod/vars" title="vars" class="ellipsis">vars</a></li>
  <li><a href="https://metacpan.org/pod/warnings" title="warnings" class="ellipsis">warnings</a></li>
  <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Carp::Assert/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Carp%3A%3AAssert">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Carp-Assert">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/YVES/Carp-Assert-0.22/view/lib/Carp/Assert.pm">This version</a>
    </li>
    <li>
      <a href="./Carp::Assert.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/MIKKOI"><img src="https://www.gravatar.com/avatar/9585d662ef1303e24a1490916f5198b7?d=identicon&amp;s=20" title="MIKKOI" alt="MIKKOI"></a>
<a class="display-all" href="https://metacpan.org/author/KHEDIN"><img src="https://www.gravatar.com/avatar/161d7953c4cd4b2bcfce883cad9f3a92?d=identicon&amp;s=20" title="KHEDIN" alt="KHEDIN"></a>
<a class="display-all" href="https://metacpan.org/author/RWP"><img src="https://www.gravatar.com/avatar/7110eb2389e69a066d9d7cad7a1cc2bf?d=identicon&amp;s=20" title="RWP" alt="RWP"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Carp-Assert/plussers">3 PAUSE users</a>
</div>
<div>
    3 non-PAUSE users
</div>
</div>
    </li>
    <li>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/YVES" class="author-name">Yves</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Carp/Assert.pm&#39;" class="">
<option
  selected
  value="YVES/Carp-Assert-0.22"
>0.22
  (YVES on 2023-03-04)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.20"
>0.20
  (MSCHWERN on 2007-01-05)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.19"
>0.19
  (MSCHWERN on 2007-01-02)</option>
<optgroup label="BackPAN">'
<option
  
  value="NEILB/Carp-Assert-0.21"
>0.21
  (NEILB on 2014-06-25)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.18"
>0.18
  (MSCHWERN on 2004-03-03)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.17"
>0.17
  (MSCHWERN on 2001-10-01)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.16"
>0.16
  (MSCHWERN on 2001-09-09)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.15"
>0.15
  (MSCHWERN on 2001-08-22)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.13"
>0.13
  (MSCHWERN on 2001-02-09)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.12"
>0.12
  (MSCHWERN on 2001-02-07)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.11"
>0.11
  (MSCHWERN on 2000-06-02)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.10"
>0.10
  (MSCHWERN on 2000-03-13)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.08"
>0.08
  (MSCHWERN on 1999-12-23)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.07"
>0.07
  (MSCHWERN on 1999-10-13)</option>
<option
  
  value="MSCHWERN/Carp-Assert-0.06"
>0.06
  (MSCHWERN on 1999-04-29)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Carp-Assert">Carp-Assert-0.22</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage three &#10;
          • 38 direct dependents &#10;          • 292 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Carp-Assert-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Carp-Assert-0.22">
    <input type="hidden" name="author" value="YVES">
    <input type="hidden" name="distribution" value="Carp-Assert">
    <button type="submit" class="favorite highlight"><span>6</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Carp::Assert.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>6</span> ++</a>
</div>
   / <span>Carp::Assert</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Carp::Assert.html#NAME">NAME</a></li>
  <li><a href="./Carp::Assert.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Carp::Assert.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Carp::Assert.html#FUNCTIONS">FUNCTIONS</a></li>
  <li><a href="./Carp::Assert.html#Debugging-vs-Production">Debugging vs Production</a></li>
  <li><a href="./Carp::Assert.html#Differences-from-ANSI-C">Differences from ANSI C</a></li>
  <li><a href="./Carp::Assert.html#EFFICIENCY">EFFICIENCY</a></li>
  <li><a href="./Carp::Assert.html#ENVIRONMENT">ENVIRONMENT</a></li>
  <li><a href="./Carp::Assert.html#BUGS,-CAVETS-and-other-MUSINGS">BUGS, CAVETS and other MUSINGS</a>
    <ul>
      <li><a href="./Carp::Assert.html#Conflicts-with-POSIX.pm">Conflicts with POSIX.pm</a></li>
      <li><a href="./Carp::Assert.html#affirm-and-$%5ES">affirm and $^S</a></li>
      <li><a href="./Carp::Assert.html#missing-if-DEBUG">missing if DEBUG</a></li>
    </ul>
  </li>
  <li><a href="./Carp::Assert.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Carp::Assert.html#REPOSITORY">REPOSITORY</a></li>
  <li><a href="./Carp::Assert.html#COPYRIGHT">COPYRIGHT</a></li>
  <li><a href="./Carp::Assert.html#AUTHOR">AUTHOR</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Carp::Assert - executable comments</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    # Assertions are on.
    use Carp::Assert;

    $next_sunrise_time = sunrise();

    # Assert that the sun must rise in the next 24 hours.
    assert(($next_sunrise_time - time) &lt; 24*60*60) if DEBUG;

    # Assert that your customer&#39;s primary credit card is active
    affirm {
        my @cards = @{$customer-&gt;credit_cards};
        $cards[0]-&gt;is_active;
    };


    # Assertions are off.
    no Carp::Assert;

    $next_pres = divine_next_president();

    # Assert that if you predict Dan Quayle will be the next president
    # your crystal ball might need some polishing.  However, since
    # assertions are off, IT COULD HAPPEN!
    shouldnt($next_pres, &#39;Dan Quayle&#39;) if DEBUG;</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<pre><code>    &quot;We are ready for any unforseen event that may or may not 
    occur.&quot;
        - Dan Quayle</code></pre>

<p>Carp::Assert is intended for a purpose like the ANSI C library <a href="http://en.wikipedia.org/wiki/Assert.h">assert.h</a>. If you&#39;re already familiar with assert.h, then you can probably skip this and go straight to the FUNCTIONS section.</p>

<p>Assertions are the explicit expressions of your assumptions about the reality your program is expected to deal with, and a declaration of those which it is not. They are used to prevent your program from blissfully processing garbage inputs (garbage in, garbage out becomes garbage in, error out) and to tell you when you&#39;ve produced garbage output. (If I was going to be a cynic about Perl and the user nature, I&#39;d say there are no user inputs but garbage, and Perl produces nothing but...)</p>

<p>An assertion is used to prevent the impossible from being asked of your code, or at least tell you when it does. For example:</p>

<pre><code>    # Take the square root of a number.
    sub my_sqrt {
        my($num) = shift;

        # the square root of a negative number is imaginary.
        assert($num &gt;= 0);

        return sqrt $num;
    }</code></pre>

<p>The assertion will warn you if a negative number was handed to your subroutine, a reality the routine has no intention of dealing with.</p>

<p>An assertion should also be used as something of a reality check, to make sure what your code just did really did happen:</p>

<pre><code>    open(FILE, $filename) || die $!;
    @stuff = &lt;FILE&gt;;
    @stuff = do_something(@stuff);

    # I should have some stuff.
    assert(@stuff &gt; 0);</code></pre>

<p>The assertion makes sure you have some @stuff at the end. Maybe the file was empty, maybe do_something() returned an empty list... either way, the assert() will give you a clue as to where the problem lies, rather than 50 lines down at when you wonder why your program isn&#39;t printing anything.</p>

<p>Since assertions are designed for debugging and will remove themelves from production code, your assertions should be carefully crafted so as to not have any side-effects, change any variables, or otherwise have any effect on your program. Here is an example of a bad assertation:</p>

<pre><code>    assert($error = 1 if $king ne &#39;Henry&#39;);  # Bad!</code></pre>

<p>It sets an error flag which may then be used somewhere else in your program. When you shut off your assertions with the $DEBUG flag, $error will no longer be set.</p>

<p>Here&#39;s another example of <b>bad</b> use:</p>

<pre><code>    assert($next_pres ne &#39;Dan Quayle&#39; or goto Canada);  # Bad!</code></pre>

<p>This assertion has the side effect of moving to Canada should it fail. This is a very bad assertion since error handling should not be placed in an assertion, nor should it have side-effects.</p>

<p>In short, an assertion is an executable comment. For instance, instead of writing this</p>

<pre><code>    # $life ends with a &#39;!&#39;
    $life = begin_life();</code></pre>

<p>you&#39;d replace the comment with an assertion which <b>enforces</b> the comment.</p>

<pre><code>    $life = begin_life();
    assert( $life =~ /!$/ );</code></pre>

<h1 id="FUNCTIONS">FUNCTIONS</h1>

<dl>

<dt id="assert"><b>assert</b></dt>
<dd>

<pre><code>    assert(EXPR) if DEBUG;
    assert(EXPR, $name) if DEBUG;</code></pre>

<p>assert&#39;s functionality is effected by compile time value of the DEBUG constant, controlled by saying <code>use Carp::Assert</code> or <code>no Carp::Assert</code>. In the former case, assert will function as below. Otherwise, the assert function will compile itself out of the program. See <a href="./Carp::Assert.html#Debugging-vs-Production">&quot;Debugging vs Production&quot;</a> for details.</p>

<p>Give assert an expression, assert will Carp::confess() if that expression is false, otherwise it does nothing. (DO NOT use the return value of assert for anything, I mean it... really!).</p>

<p>The error from assert will look something like this:</p>

<pre><code>    Assertion failed!
            Carp::Assert::assert(0) called at prog line 23
            main::foo called at prog line 50</code></pre>

<p>Indicating that in the file &quot;prog&quot; an assert failed inside the function main::foo() on line 23 and that foo() was in turn called from line 50 in the same file.</p>

<p>If given a $name, assert() will incorporate this into your error message, giving users something of a better idea what&#39;s going on.</p>

<pre><code>    assert( Dogs-&gt;isa(&#39;People&#39;), &#39;Dogs are people, too!&#39; ) if DEBUG;
    # Result - &quot;Assertion (Dogs are people, too!) failed!&quot;</code></pre>

</dd>
<dt id="affirm"><b>affirm</b></dt>
<dd>

<pre><code>    affirm BLOCK if DEBUG;
    affirm BLOCK $name if DEBUG;</code></pre>

<p>Very similar to assert(), but instead of taking just a simple expression it takes an entire block of code and evaluates it to make sure its true. This can allow more complicated assertions than assert() can without letting the debugging code leak out into production and without having to smash together several statements into one.</p>

<pre><code>    affirm {
        my $customer = Customer-&gt;new($customerid);
        my @cards = $customer-&gt;credit_cards;
        grep { $_-&gt;is_active } @cards;
    } &quot;Our customer has an active credit card&quot;;</code></pre>

<p>affirm() also has the nice side effect that if you forgot the <code>if DEBUG</code> suffix its arguments will not be evaluated at all. This can be nice if you stick affirm()s with expensive checks into hot loops and other time-sensitive parts of your program.</p>

<p>If the $name is left off and your Perl version is 5.6 or higher the affirm() diagnostics will include the code begin affirmed.</p>

</dd>
<dt id="should"><b>should</b></dt>
<dd>

</dd>
<dt id="shouldnt"><b>shouldnt</b></dt>
<dd>

<pre><code>    should  ($this, $shouldbe)   if DEBUG;
    shouldnt($this, $shouldntbe) if DEBUG;</code></pre>

<p>Similar to assert(), it is specially for simple &quot;this should be that&quot; or &quot;this should be anything but that&quot; style of assertions.</p>

<p>Due to Perl&#39;s lack of a good macro system, assert() can only report where something failed, but it can&#39;t report <i>what</i> failed or <i>how</i>. should() and shouldnt() can produce more informative error messages:</p>

<pre><code>    Assertion (&#39;this&#39; should be &#39;that&#39;!) failed!
            Carp::Assert::should(&#39;this&#39;, &#39;that&#39;) called at moof line 29
            main::foo() called at moof line 58</code></pre>

<p>So this:</p>

<pre><code>    should($this, $that) if DEBUG;</code></pre>

<p>is similar to this:</p>

<pre><code>    assert($this eq $that) if DEBUG;</code></pre>

<p>except for the better error message.</p>

<p>Currently, should() and shouldnt() can only do simple eq and ne tests (respectively). Future versions may allow regexes.</p>

</dd>
</dl>

<h1 id="Debugging-vs-Production"><a id="Debugging"></a>Debugging vs Production</h1>

<p>Because assertions are extra code and because it is sometimes necessary to place them in &#39;hot&#39; portions of your code where speed is paramount, Carp::Assert provides the option to remove its assert() calls from your program.</p>

<p>So, we provide a way to force Perl to inline the switched off assert() routine, thereby removing almost all performance impact on your production code.</p>

<pre><code>    no Carp::Assert;  # assertions are off.
    assert(1==1) if DEBUG;</code></pre>

<p>DEBUG is a constant set to 0. Adding the &#39;if DEBUG&#39; condition on your assert() call gives perl the cue to go ahead and remove assert() call from your program entirely, since the if conditional will always be false.</p>

<pre><code>    # With C&lt;no Carp::Assert&gt; the assert() has no impact.
    for (1..100) {
        assert( do_some_really_time_consuming_check ) if DEBUG;
    }</code></pre>

<p>If <code>if DEBUG</code> gets too annoying, you can always use affirm().</p>

<pre><code>    # Once again, affirm() has (almost) no impact with C&lt;no Carp::Assert&gt;
    for (1..100) {
        affirm { do_some_really_time_consuming_check };
    }</code></pre>

<p>Another way to switch off all asserts, system wide, is to define the NDEBUG or the PERL_NDEBUG environment variable.</p>

<p>You can safely leave out the &quot;if DEBUG&quot; part, but then your assert() function will always execute (and its arguments evaluated and time spent). To get around this, use affirm(). You still have the overhead of calling a function but at least its arguments will not be evaluated.</p>

<h1 id="Differences-from-ANSI-C"><a id="Differences"></a>Differences from ANSI C</h1>

<p>assert() is intended to act like the function from ANSI C fame. Unfortunately, due to Perl&#39;s lack of macros or strong inlining, it&#39;s not nearly as unobtrusive.</p>

<p>Well, the obvious one is the &quot;if DEBUG&quot; part. This is cleanest way I could think of to cause each assert() call and its arguments to be removed from the program at compile-time, like the ANSI C macro does.</p>

<p>Also, this version of assert does not report the statement which failed, just the line number and call frame via Carp::confess. You can&#39;t do <code>assert(&#39;$a == $b&#39;)</code> because $a and $b will probably be lexical, and thus unavailable to assert(). But with Perl, unlike C, you always have the source to look through, so the need isn&#39;t as great.</p>

<h1 id="EFFICIENCY">EFFICIENCY</h1>

<p>With <code>no Carp::Assert</code> (or NDEBUG) and using the <code>if DEBUG</code> suffixes on all your assertions, Carp::Assert has almost no impact on your production code. I say almost because it does still add some load-time to your code (I&#39;ve tried to reduce this as much as possible).</p>

<p>If you forget the <code>if DEBUG</code> on an <code>assert()</code>, <code>should()</code> or <code>shouldnt()</code>, its arguments are still evaluated and thus will impact your code. You&#39;ll also have the extra overhead of calling a subroutine (even if that subroutine does nothing).</p>

<p>Forgetting the <code>if DEBUG</code> on an <code>affirm()</code> is not so bad. While you still have the overhead of calling a subroutine (one that does nothing) it will <b>not</b> evaluate its code block and that can save a lot.</p>

<p>Try to remember the <b>if DEBUG</b>.</p>

<h1 id="ENVIRONMENT">ENVIRONMENT</h1>

<dl>

<dt id="NDEBUG">NDEBUG</dt>
<dd>

<p>Defining NDEBUG switches off all assertions. It has the same effect as changing &quot;use Carp::Assert&quot; to &quot;no Carp::Assert&quot; but it effects all code.</p>

</dd>
<dt id="PERL_NDEBUG">PERL_NDEBUG</dt>
<dd>

<p>Same as NDEBUG and will override it. Its provided to give you something which won&#39;t conflict with any C programs you might be working on at the same time.</p>

</dd>
</dl>

<h1 id="BUGS,-CAVETS-and-other-MUSINGS"><a id="BUGS"></a><a id="BUGS--CAVETS-and-other-MUSINGS"></a>BUGS, CAVETS and other MUSINGS</h1>

<h2 id="Conflicts-with-POSIX.pm"><a id="Conflicts"></a>Conflicts with <code>POSIX.pm</code></h2>

<p>The <code>POSIX</code> module exports an <code>assert</code> routine which will conflict with <code>Carp::Assert</code> if both are used in the same namespace. If you are using both together, prevent <code>POSIX</code> from exporting like so:</p>

<pre><code>    use POSIX ();
    use Carp::Assert;</code></pre>

<p>Since <code>POSIX</code> exports way too much, you should be using it like that anyway.</p>

<h2 id="affirm-and-$^S"><a id="affirm1"></a><a id="affirm-and--S"></a><code>affirm</code> and <code>$^S</code></h2>

<p>affirm() mucks with the expression&#39;s caller and it is run in an eval so anything that checks $^S will be wrong.</p>

<h2 id="missing-if-DEBUG"><a id="missing"></a>missing <code>if DEBUG</code></h2>

<p>It would be nice if we could warn about missing <code>if DEBUG</code>.</p>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<p><a href="http://en.wikipedia.org/wiki/Assert.h">assert.h</a> - the wikipedia page about <code>assert.h</code>.</p>

<p><a href="https://metacpan.org/pod/Carp::Assert::More">Carp::Assert::More</a> provides a set of convenience functions that are wrappers around <code>Carp::Assert</code>.</p>

<p><a href="https://metacpan.org/pod/Sub::Assert">Sub::Assert</a> provides support for subroutine pre- and post-conditions. The documentation says it&#39;s slow.</p>

<p><a href="https://metacpan.org/pod/PerlX::Assert">PerlX::Assert</a> provides compile-time assertions, which are usually optimised away at compile time. Currently part of the <a href="https://metacpan.org/pod/Moops">Moops</a> distribution, but may get its own distribution sometime in 2014.</p>

<p><a href="https://metacpan.org/pod/Devel::Assert">Devel::Assert</a> also provides an <code>assert</code> function, for Perl &gt;= 5.8.1.</p>

<p><a href="https://metacpan.org/pod/assertions">assertions</a> provides an assertion mechanism for Perl &gt;= 5.9.0.</p>

<h1 id="REPOSITORY">REPOSITORY</h1>

<p><a href="https://github.com/schwern/Carp-Assert">https://github.com/schwern/Carp-Assert</a></p>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright 2001-2007 by Michael G Schwern &lt;schwern@pobox.com&gt;.</p>

<p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>

<p>See <i>http://dev.perl.org/licenses/</i></p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Michael G Schwern &lt;schwern@pobox.com&gt;</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Carp::Assert, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Carp::Assert</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Carp::Assert</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Carp::Assert.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
